"""
  Created by Amor on 2018-08-18
"""
import json
import random
import requests

__author__ = '骆杨'


class YunPian(object):
    def __init__(self, api_key):
        self.api_key = api_key
        self.single_url = 'https://sms.yunpian.com/v2/sms/single_send.json'

    def send_sms(self, code, mobile):
        parmas = {
            'apikey': self.api_key,
            'mobile': mobile,
            'text': '【慕学生鲜】您的验证码是{code}。如非本人操作，请忽略本短信'.format(code=code)
        }

        response = requests.post(self.single_url, data=parmas)
        return json.loads(response.text)

    @staticmethod
    def generate_code():
        seeds = '1234567890'
        random_str = []
        for i in range(6):
            random_str.append(random.choice(seeds))
        return ''.join(random_str)
